import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadPoolExecutor{
    private List<Thread> threadList=new ArrayList<>();
    private BlockingQueue<Runnable> queue=new ArrayBlockingQueue<>(1000);
    public MyThreadPoolExecutor(int n){
        for (int i=0;i<n;i++){
            Thread t=new Thread(()->{
                while (true){
                    try {
                        Runnable runnable=queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            t.start();
            threadList.add(t);
        }

    }
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
}



























/*
import java.util.PriorityQueue;
class MyTimertask implements Comparable<MyTimertask>{
    private Runnable runnable;
    private long time;

    public MyTimertask(Runnable runnable,long delay){
        this.runnable=runnable;
        this.time=System.currentTimeMillis()+delay;
    }

    public long getTime() {
        return time;
    }
    public void run(){
        runnable.run();
    }
    @Override
    public int compareTo(MyTimertask o) {
        return (int) (this.time-o.time);
    }
}
class MyTimer{
    private Thread t=null;
    private PriorityQueue<MyTimertask> queue=new PriorityQueue<>();
    private Object locker=new Object();


    //添加任务
    public void schedule(Runnable runnable,long delay){
        MyTimertask task=new MyTimertask(runnable,delay);
        queue.offer(task);
    }


    public MyTimer(){
        t=new Thread(()->{
           try {
               synchronized (locker){
                   while (true){
                       while (queue.isEmpty()){
                           locker.wait();
                       }
                       MyTimertask curTask=queue.peek();
                       if (System.currentTimeMillis()>=curTask.getTime()){
                           queue.poll();
                           curTask.run();
                       }else {
                           locker.wait(curTask.getTime()-System.currentTimeMillis());
                       }
                   }
               }
           }catch (InterruptedException e){
               e.printStackTrace();
           }
        });
        t.start();
    }
}

*/
































/*
class MyBlockingQueue<T>{
    private Object[] elems;
    private Object locker=new Object();
    public MyBlockingQueue(int capcity){
        this.elems=new String[capcity];
    }
    private int head;
    private int tail;
    private int count;
    public void put(T t) throws InterruptedException {
       synchronized (locker){
           while (count==elems.length){
               locker.wait();
           }
           elems[tail]=t;
           tail++;
           if (tail==elems.length){
               tail=0;
           }
           count++;
           locker.notify();
       }
    }


    public T take() throws InterruptedException {
        T elem=null;
       synchronized (locker){
           while (count==0){
               locker.wait();
           }
           elem= (T) elems[head];
           head++;
           if (head==elems.length){
               head=0;
           }
           count--;
           locker.notify();
       }
        return elem;
    }
}


*/














/*class SingletonLazy{
    //懒汉模式
    private static volatile SingletonLazy instance=null;
    private static Object locker=new Object();

    public static SingletonLazy getInstance() {
        if (instance==null){
            synchronized (locker){
                if (instance==null){
                    instance=new SingletonLazy();
                }
            }
        }
        return instance;
    }
}*/



/*
class Singleton{
    //饿汉模式
    private static Singleton instance=new Singleton();

    public static Singleton getInstance() {
        return instance;
    }
    private Singleton(){}
}

*/


public class Test {
}
